angular.module('mamApp').controller('commonDimensionModalController', ['$scope', 'AlbumManager', '$uibModalInstance', 'TagsManager', 'param',
    function ($scope, AlbumManager, $uibModalInstance, TagsManager, param) {

        var dimensionId = "";
        $scope.formData = {status: 2};
        if (param.commonDimens) {
            $scope.formData.dimensionsName = param.commonDimens.dimensionsName;
            $scope.formData.status = param.commonDimens.status;
            dimensionId = param.commonDimens.dimensionId;
        }

        $scope.modelOk = function () {
            if (dimensionId) {
                TagsManager.commonDimensionsEdit(dimensionId, $scope.formData).then(function (result) {
                    if (result.data.c == "s") {
                        $uibModalInstance.close("ok");

                    } else {
                        $scope.nameCheck = true;
                        $scope.message=result.data.i;
                        //$uibModalInstance.close("error");

                    }
                })

            } else {
                TagsManager.commonDimensionsAdd($scope.formData).then(function (result) {
                    if (result.data.c == "s") {
                        $uibModalInstance.close("ok");

                    } else {
                        $scope.nameCheck = true;
                        $scope.message=result.data.i;
                        //$uibModalInstance.close("error");

                    }
                })
            }


        };

        $scope.modelCancel = function () {
            $uibModalInstance.close("cancel");
        };


    }])

